      1  import java.io.InputStream;

      2  import java.io.IOException;

      3  import java.io.OutputStream;

      4  import java.io.PrintWriter;

      5  import java.net.Socket;

      6  import java.util.Scanner;

      7

      8  /**

      9     This program tests the bank server.

     10  */

     11  public class BankClient

     12  {

     13     public static void main(String[] args) throws IOException

     14     {

     15        final int SBAP_PORT = 8888;

     16        Socket s = new Socket("localhost", SBAP_PORT);

     17        InputStream instream = s.getInputStream();

     18        OutputStream outstream = s.getOutputStream();

     19        Scanner in = new Scanner(instream);

     20        PrintWriter out = new PrintWriter(outstream);

     21

     22        String command = "DEPOSIT 3 1000\n";

     23        System.out.print("Sending: " + command);

     24        out.print(command);

     25        out.flush();

     26        String response = in.nextLine();

     27        System.out.println("Receiving: " + response);

     28

     29        command = "WITHDRAW 3 500\n";

     30        System.out.print("Sending: " + command);

     31        out.print(command);

     32        out.flush();

     33        response = in.nextLine();

     34        System.out.println("Receiving: " + response);

     35

     36        command = "QUIT\n";

     37        System.out.print("Sending: " + command);

     38        out.print(command);

     39        out.flush();

     40

     41        s.close();

     42     }

     43  }

     44

     45

     46

     47

     48